package org.flown.shop.entity;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.util.Base64;


@Data
public class User
{
    private int id;
    private String nickname;
    @NotNull
    private String username;
    @NotNull
    private String password;

    public User(){super();this.id = 0;}
    public User(String username, String password){this(null, username, password);}
    public User(String nickname, String username, String password){this(0, nickname, username, password);}
    public User(int id, String nickname, String username, String password)
    {
        this.id = id;
        this.nickname = nickname;
        this.username = username;
        this.password = password;
    }


    public String asJSONString()
    {
        try {
            return new ObjectMapper().writeValueAsString(this);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return null;
        }
    }
    public void setID(int id) {this.id = id;}
    public int getID() {return this.id;}
    public String getBase64Username() {return Base64.getEncoder().encodeToString(this.username.getBytes());}
    public String getBase64Password() {return Base64.getEncoder().encodeToString(this.password.getBytes());}

}


